<template>
  <div>
    <div class="block" style="width: 100px; height: 100px; margin-left: 50px; margin-top: 20px;">
      <el-avatar :size="60">
        <img :src=url />
        <!-- 显示用户名 -->
      </el-avatar>
      <p style="font-size: 15px;color: black;">用户：{{ this.user["userName"] }}</p>
    </div>
    <el-container>
      <el-aside width="15%">
        <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" @select="changesiderpage"
          style="margin-top: 30px;">
          <el-menu-item index="uploadimg">
            <i class="el-icon-upload"></i>
            <span slot="title">上传图片</span>
          </el-menu-item>
          <el-menu-item index="imglist">
            <i class="el-icon-picture"></i>
            <span slot="title">图片列表</span>
          </el-menu-item>
          <el-menu-item index="user">
            <i class="el-icon-s-data"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          <el-menu-item index="point">
            <i class="el-icon-s-data"></i>
            <span slot="title">物流线路</span>
          </el-menu-item>
        </el-menu>

      </el-aside>

      <el-container>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>

<script>
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: true,
      fit: 'fill',
      url: "https://pic2.zhimg.com/80/v2-3b5b63db81c491823d4ce635bb74cd71_1440w.webp",
      user: {},
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    changesiderpage(path) {
      this.$router.push(path)
    },
    // 获取后台存储的用户名，但是读取失败
    // 读取bb={"aa":""}对象用bb["aa"]现在赋值给user的内容就是{"userName":"lzj","pwd":"123","captcha":"6apn"}
    putname() {
      let res1 = localStorage.getItem('user')
      // console.log(res1);
      this.user = JSON.parse(res1);
      // console.log(this.user["userName"]);
    }
  },
  mounted() {
    this.sidebarItem = this.$route.name;
    this.putname();

  }

};
</script>

